//package com.xnyy.lottery.config;
//
//import com.xnyy.lottery.security.JWTLogoutSuccessHandler;
//import com.xnyy.lottery.security.JwtAccessDeniedHandler;
//import com.xnyy.lottery.security.JwtAuthenticationEntryPoint;
//import com.xnyy.lottery.security.JwtAuthenticationFilter;
//import com.xnyy.lottery.security.LoginFailureHandler;
//import com.xnyy.lottery.security.LoginSuccessHandler;
//import com.xnyy.lottery.security.UserDetailsServiceImpl;
//import lombok.RequiredArgsConstructor;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.config.http.SessionCreationPolicy;
//import org.springframework.security.crypto.factory.PasswordEncoderFactories;
//import org.springframework.security.crypto.password.PasswordEncoder;
//
//import javax.annotation.Resource;
//
///**
// * @description: 安全配置
// * @auther: Administrator
// * @date: 2022/9/16 02:17
// */
//@Configuration
//@EnableWebSecurity
//@RequiredArgsConstructor
//public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
//    @Resource
//    private LoginFailureHandler loginFailureHandler;
//    @Resource
//    private LoginSuccessHandler loginSuccessHandler;
//    @Resource
//    private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
//    @Resource
//    private JwtAccessDeniedHandler jwtAccessDeniedHandler;
//    @Resource
//    private UserDetailsServiceImpl userDetailService;
//    @Resource
//    private JWTLogoutSuccessHandler jwtLogoutSuccessHandler;
//
//    @Bean
//    public PasswordEncoder passwordEncoder() {
//        return PasswordEncoderFactories.createDelegatingPasswordEncoder();
//    }
//
//    @Bean
//    JwtAuthenticationFilter jwtAuthenticationFilter() throws Exception {
//        JwtAuthenticationFilter jwtAuthenticationFilter = new JwtAuthenticationFilter(authenticationManager());
//        return jwtAuthenticationFilter;
//    }
//
//    private static final String[] URL_WHITELIST = {
//            "/**",
////            "/login",
////            "/logout",
////            "/favicon.ico"
//    };
//
//    @Override
//    public void configure(HttpSecurity http) throws Exception {
//        http.cors().disable().csrf().disable()
//                .formLogin().disable()
//                .authorizeRequests()
//                .antMatchers(URL_WHITELIST).permitAll()
//                .anyRequest().authenticated();
//
////        http.cors().and().csrf().disable()
////                // 登录配置
////                .formLogin()
////                .successHandler(loginSuccessHandler)
////                .failureHandler(loginFailureHandler)
////
////                .and()
////                .logout()
////                .logoutSuccessHandler(jwtLogoutSuccessHandler)
////
////                // 禁用session
////                .and()
////                .sessionManagement()
////                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
////                // 配置拦截规则
////                .and()
////                .authorizeRequests()
////                .antMatchers(URL_WHITELIST).permitAll()
////                .anyRequest().authenticated()
////                // 异常处理器
////                .and()
////                .exceptionHandling()
////                .authenticationEntryPoint(jwtAuthenticationEntryPoint)
////                .accessDeniedHandler(jwtAccessDeniedHandler)
////
////                // 配置自定义的过滤器
////                .and()
////                .addFilter(jwtAuthenticationFilter());
//
//        //.requestMatchers(AbstractRequestMatcherRegistry::anyRequest)
//        //.formLogin(a -> {
//        //    a.defaultSuccessUrl("/");
//        //})
//        //.logout(a -> a
//        //                .addLogoutHandler(new CustomLogoutHandler())
//        //                .logoutSuccessUrl("/login") //与下面配置二选一
//        //        //.logoutSuccessHandler(new CustomLogoutSuccessHandler())
//        //)
//        //.authorizeRequests(a ->
//        //        a.antMatchers("/index", "/login").permitAll()
//        //                .anyRequest().authenticated()
//        //)
//        //.headers(a ->
//        //        a.frameOptions()
//        //                .sameOrigin()
//        //).csrf().disable();
//    }
//
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        auth.userDetailsService(userDetailService);
//    }
//}
